package com.java.tutorials.jdk7.jdk7;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.lang.management.RuntimeMXBean;
import java.util.List;
/**
 * Created by xuzhike on 2016/1/27.
 * http://www.java2s.com/Code/Java/JDK-7/UsingtheplatformMXBeansforaJVMforsystemandprocessloadmonitoring.htm
 * Using the platform MXBeans for a JVM for system and process load monitoring
 */
public class MXBeansTest {
    public static void main(String[] args) {
        RuntimeMXBean mxBean = ManagementFactory
                .getPlatformMXBean(RuntimeMXBean.class);

        System.out.println("JVM Name: " + mxBean.getName());
        System.out.println("JVM Specification Name: " + mxBean.getSpecName());
        System.out.println("JVM Specification Version: " + mxBean.getSpecVersion());
        System.out.println("JVM Implemenation Name: " + mxBean.getVmName());
        System.out.println("JVM Implemenation Vendor: " + mxBean.getVmVendor());
        System.out.println("JVM Implemenation Version: " + mxBean.getVmVersion());

        // Using the getPlatformMXBeans method
        List<OperatingSystemMXBean> list = ManagementFactory
                .getPlatformMXBeans(OperatingSystemMXBean.class);
        System.out.println("size: " + list.size());
        for (OperatingSystemMXBean bean : list) {
            System.out.println("Operating System Name: " + bean.getName());
            System.out.println("Operating System Architecture: " + bean.getArch());
            System.out.println("Operating System Version: " + bean.getVersion());
        }

    }
}
